var TOOL = {version:'1.0'};
(function(HH){
    HH.check = {
        isNickname: function(str) {
            var nickReg = /^[\u4e00-\u9fa5A-Za-z0-9-_]+$/;
            return nickReg.test(str)
        },
        isEmail: function(str) {
            var emailReg = /^[a-z0-9][\w\.]*@([a-z0-9][a-z0-9-]*\.)+[a-z]{2,5}$/i;
            return emailReg.test(str)
        },
        isMobile: function(str) {
            var mobileReg = /^1(2[0-9]|3[0-9]|4[0-9]|5[0-9]|6[0-9]|7[0-9]|8[0-9]|9[0-9])\d{8}$/;
            return mobileReg.test(str)
        },
        isBank: function(str) {
            // var validateBankCard = /^([1-9]{1})(\d{14}|\d{18})$/;
            var validateBankCard = /[1-9]\d{12,18}/;
            // /^([1-9]{1})(\d{15}|\d{16}|\d{18})$/
            return validateBankCard.test(str)
        },
        isUrl: function(str) {
            var urlReg = /^http:\/\/([\w-]+\.)+[\w-]+(\/[\w-.\/?%&=]*)?$/;
            return urlReg.test(str)
        },
        isNum: function(str) {
            var numReg = /^[0-9]\d*$/;
            return numReg.test(str)
        },
        isPrice: function(str) {
            var priceReg = /^(d*.d{0,2}|d+).*$/;
            return priceReg.test(str)
        },
        isNull: function(obj) {
            if(!obj || typeof(obj) == "undefined" || obj == "" || obj === "undefined") {
                return true;
            }
            return false;
        },
        isPwd: function(str) {
            var pwReg = /^[A-Za-z0-9#@!?,-~%^&*\+_=\.\/:\\]{4,16}$/;
            return pwReg.test(str)
        },
        sfzhao: function(str) {
            var sfzReg = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|[xX])$/;
            return sfzReg.test(str);
        },
        //表情符号
        regStrFn: function (str) {
            /*let reg = /([^\u0020-\u007E\u00A0-\u00BE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\u0080-\u009F\u2000-\u201f\u2026\u2022\u20ac\r\n])|(\s)/g,indexArr = reg.exec(str);
            if (str.match(reg)) {
                str = str.replace(reg, '');
            }
            let obj = { val: str, index: indexArr };
            return obj;*/
            return str;
        },
        isJSON:function (str) {
            if (typeof str == 'string') {
                try {
                    var obj=JSON.parse(str);
                    if(typeof obj == 'object' && obj ){
                        return true;
                    }else{
                        return false;
                    }
                } catch(e) {
                    return false;
                }
            }
        },
        isObj:function(obj){
            if(typeof obj == 'object'){
                return true;
            }
            return false;
        },
		isEmptyObj:function(obj){//判断是否为空对象
			for(var key in obj){
				return false;
			}
			return true;
		},
    };

	//小数点后保留两位小数
	HH.toDecimal2 = function(x, k) {
		k = 2;
		var f = parseFloat(x);
		if (isNaN(f)) {
			return false;
		}
		var f = Math.round(x * 100) / 100;
		var s = f.toString();
		var rs = s.indexOf('.');
		if (rs < 0) {
			rs = s.length;
			s += '.'
		}
		while (s.length <= rs + k) {
			s += '0'
		}
		return s
	};

	//高德坐标转百度（传入经度、纬度）
	HH.bd_encrypt = function(bd_lng, bd_lat) {
        var X_PI = Math.PI * 3000.0 / 180.0;
        var x = bd_lng - 0.0065;
        var y = bd_lat - 0.006;
        var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI);
        var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * X_PI);
        var gg_lng = z * Math.cos(theta);
        var gg_lat = z * Math.sin(theta);
        return {lon: gg_lng, lat: gg_lat}
	};

	//百度坐标转高德（传入经度、纬度）
	HH.bd_decrypt = function(gg_lng, gg_lat) {
        var X_PI = Math.PI * 3000.0 / 180.0;
        var x = gg_lng, y = gg_lat;
        var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * X_PI);
        var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * X_PI);
        var bd_lng = z * Math.cos(theta) + 0.0065;
        var bd_lat = z * Math.sin(theta) + 0.006;
        return {
            lat: bd_lat,
            lon: bd_lng
        };
	};
    HH.priceToStr =  function(price) {
        price = HH.toDecimal2(price);
        var xshu = price.split('.');
        return '￥<em>' + xshu[0] + '</em><i>.' + xshu[1] + '</i>'
    }
})(TOOL);
